package com.nit.mapper;

import com.nit.dto.ShopDTO;
import com.nit.entity.ShopEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ShopMapper {

    @Select("<script> " +
            "SELECT COUNT(*) " +
            "FROM tb_shop " +
            "WHERE is_delete = 0 " +
            "<if test='shopName != null'> AND shop_name LIKE CONCAT('%', #{shopName}, '%') </if>" +
            "</script> ")
    Long count4Table(@Param("shopName") Object shopName);

    @Select("<script> " +
            "SELECT " +
            "shop_id, shop_name,shop_address, user_id, gmt_create,shop_phone " +
            "FROM tb_shop " +
            "WHERE is_delete = 0 " +
            "<if test='shopName != null'> AND shop_name LIKE CONCAT('%', #{shopName}, '%') </if>" +
            "ORDER BY shop_id " +
            "LIMIT #{start}, #{length} " +
            "</script> ")
    List<ShopDTO> list4Table(@Param("start") Integer start,
                              @Param("length") Integer length,
                              @Param("shopName") Object shopName);

    @Select("SELECT shop_id " +
            "FROM tb_shop " +
            "WHERE user_id = #{userId} ")
    Long getShopIdByUserId(@Param("userId") Long userId);

    @Update("UPDATE tb_shop " +
            "SET is_delete = 1 " +
            "WHERE shop_id = #{shopId} ")
    Integer remove(@Param("shopId") Long shopId);

    @Update("UPDATE tb_shop " +
            "SET " +
            "shop_name = #{shopDTO.shopName}, shop_address = #{shopDTO.shopAddress}, " +
            "user_id = #{shopDTO.userId}, shop_phone = #{shopDTO.shopPhone} " +
            "WHERE shop_id = #{shopDTO.shopId} ")
    Integer update(@Param("shopDTO") ShopDTO shopDTO);
}
